package Fangfayinyong;

import Lambda.Employee;
import org.junit.Test;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.*;

public class Demo {

    @Test
    public void test1(){
        //测试方法引用:
        PrintStream out = System.out;
        Consumer<String> consumer=(s)-> out.println(s);

        Consumer<String> consumer1=out::println;
    }

    @Test
    public void test2(){
        Employee employee=new Employee(1,"夯昊",10,4000,"公关部");
        Supplier<String> empNameSupplier=employee::getName;
        System.out.println("姓名="+empNameSupplier.get());
        empNameSupplier=employee::getDepartment;
        System.out.println("部门="+empNameSupplier.get());
    }

    @Test
    public void test3(){

        Comparator<Integer> comparator=Integer::compare;

        System.out.println(comparator.compare(10,320));

    }

    @Test
    public void test4(){
        BiPredicate<String,String> predicate=(x,y)->x.equals(y);

        BiPredicate<String,String> containsPredicate= String::contains;

        System.out.println("A == a?" + predicate.test("A","a"));
        System.out.println("ABb 中包含 b? "+containsPredicate.test("ABb","b"));
    }

    @Test
    public void test5(){
        Supplier<Employee> employeeSupplier=()->new Employee();

        Supplier<Employee> supplier=Employee::new;

        System.out.println(supplier.get());
    }

    @Test
    public void test6(){
        Function<Integer,int[]> function=(n) -> new int[n];

        Function<Integer,int[]> createIntArray = int[]::new;
        Function<Integer,String[]> createStrArray= String[]::new;

        int[] ints = createIntArray.apply(50);
        System.out.println(ints.length);
    }
}
